local chuanjing = fk.CreateSkill{
  name = "xiaobai__chuanjing",
}

Fk:loadTranslationTable{
  ["xiaobai__chuanjing"] = "传经",
  [":xiaobai__chuanjing"] = "当你造成或受到伤害时，你可以将牌堆底的三张牌置于牌堆顶，然后可以令你或当前回合角色用所有手牌交换牌堆顶的三张牌。",
  ["#xiaobai__chuanjing-invoke"] = "传经：是否将牌堆底三张牌置于牌堆顶？",
  ["#xiaobai__chuanjing-choose"] = "传经：你可以令你或当前回合角色用所有手牌交换牌堆顶三张牌",

  ["$xiaobai__chuanjing1"] = "上弘佛道，下化众生，断见思惑。",
  ["$xiaobai__chuanjing2"] = "远历千山寻经偈，善缘不灭终能抵。",
}
---@type TrigSkelSpec<fun(self: TriggerSkill, event: DamageEvent, target: ServerPlayer, player: ServerPlayer, data: DamageData):any>
local spec = {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player,{skill_name = chuanjing.name, prompt = "#xiaobai__chuanjing-invoke"})
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for i = 1, 3, 1 do
      local id = table.remove(room.draw_pile, #room.draw_pile)
      table.insert(room.draw_pile, 1, id)
    end
    room:syncDrawPile()
    local targets = {player}
    local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn)
    if turn_event and not turn_event.data.who.dead then
      table.insertIfNeed(targets, turn_event.data.who)
    end
    local to = room:askToChoosePlayers(player, {
      targets = targets,
      max_num = 1,
      min_num = 1,
      prompt = "#xiaobai__chuanjing-choose",
      skill_name = chuanjing.name,
      skip = true})
    if #to > 0 then
      to = to[1]
      room:swapCardsWithPile(to, to:getCardIds("h"), room:getNCards(3), chuanjing.name, "Top")
    end
  end,
}

chuanjing:addEffect(fk.DamageCaused, spec)
chuanjing:addEffect(fk.DamageInflicted, spec)

return chuanjing